﻿using HardcoreGame.Content.Buffs;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.Audio;
using Terraria.ID;
using Terraria.ModLoader;

namespace HardcoreGame.Content.Projectiles.Sets.Acid
{
    public class CorrosionBullet : ModProjectile
    {
        public override void AI()
        {
            Player player = Main.player[Projectile.owner];
            Lighting.AddLight(Projectile.position, 1f, 1f, 0.5f);

        }

        public override Color? GetAlpha(Color lightColor)
        {
            return new Color(255, 255, 255, 0) * (1f - Projectile.alpha / 255f);
        }

        public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone)
        {
            if (Main.rand.NextFloat() < 0.08)
            {
                target.AddBuff(ModContent.BuffType<Corrosion>(), 240);
                for (int i = 0; i < 15; i++)
                {
                    int num6 = Dust.NewDust(target.position, target.width, target.height, DustID.TerraBlade, 0f, 0f, 100, default, 1.25f);
                    Main.dust[num6].noGravity = true;
                    Main.dust[num6].velocity *= 0.75f;
                    int num7 = Main.rand.Next(-50, 51);
                    int num8 = Main.rand.Next(-50, 51);
                    Dust dust = Main.dust[num6];
                    dust.position.X += num7;
                    Dust dust2 = Main.dust[num6];
                    dust2.position.Y += num8;
                    Main.dust[num6].velocity.X = -(float)num7 * 0.080f;
                    Main.dust[num6].velocity.Y = -(float)num8 * 0.080f;
                }
            }
        }

        public override void SetDefaults()
        {
            Projectile.CloneDefaults(ProjectileID.Bullet);
            AIType = ProjectileID.Bullet;
            Projectile.light = -1;
            Projectile.penetrate = 1;
            Projectile.ignoreWater = true;
            Projectile.extraUpdates = 3;
        }

        public override void OnKill(int timeLeft)
        {
            Collision.HitTiles(Projectile.position, Projectile.velocity, Projectile.width, Projectile.height);
            SoundEngine.PlaySound(SoundID.Item10, Projectile.position);
            for (int i = 0; i < 20; i++)
            {
                int Frost = Dust.NewDust(Projectile.Center, 1, 1, DustID.TerraBlade, 0f, 0f, 100, default, 1.3f);
                Main.dust[Frost].noGravity = true;
                Main.dust[Frost].velocity *= 2.5f;
            }
        }

    }
}

